<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>我是店铺-创建米票</title>
<link href="../template/<?=MOBAN?>/css/style.css" rel="stylesheet" type="text/css" />
<link  href="../template/<?=MOBAN?>/css/layout.css" rel="stylesheet" type="text/css" />
<link  href="../template/<?=MOBAN?>/css/comm.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/artDialog.js"></script>
<script type="text/javascript" src="../js/jquery.form.js"></script>
</head>

<body>
<?php
$modtag="shopcenter";
include("../template/".MOBAN."/header_user.tpl.php");
?>


<div class='layout_body'>
<div class="opentitle"><h1 class="shopname FLeft"><?=$_SESSION["duoduouser"]?><a href="exit.php">退出</a></h1></div>
<div class="clears"></div>
<div class="CreatL">
<ul>
<li><a href="mipiao_create.php">创建  米票管理</a></li>
<li><a href="#"> 订单管理</a></li>
<li><a href="#">送米管理</a></li>
<li><a href="#">店铺管理</a></li>

</ul>
</div>
<form id="form" name="form" action="mipiao_create.php"  method="POST" enctype="multipart/form-data">
<input id="rate" type="hidden" value="<?=$shoplevel['rate']?>">
<input id="max_money " type="hidden" value="<?=$shoplevel['max_money ']?>">
	<div class="CreatR">
		<div class="Shopnum"><?=$shopinfo['number']?></div><div class="clears"></div>
		<div class="clears"></div>
		<ul class="crearManage">
			<li>
				<em>商品/活动名称：</em>
				<input type="text" value="" class="txt">
				<span class="FLeft MarginL10">30个以内汉字（60个字符）</span>
				<div class="clears"></div>
			</li>
			
			<li>
				<em>活动图片：</em>
				<input type="button" class="clickupdate" onclick="uploadimg()"/>为了更好的展示活动，请上传一张图片<br />最大尺寸300x300,小于100K
				<input type="hidden" name="img" id="activityimg"  value=""/>
				<div class="clears"></div>
			</li>
			<li>
				<em>商品价格：</em>
				<input id="goodsprice" name="goodsprice" type="text" value="" class="txt">元
				<div class="clears"></div>
			</li>
			<li>
				<em>兑换规则：</em>
				<input id="rule1" name="rule" type="radio" value="0" checked/>消费一元送
				<input id="songmi_dongtai" name="songmi" type="text" /> 米
				<span class="grew999">大于1的整数</span>
				<div class="clears"></div>
			</li>
			<li>
				<em>&nbsp;</em>
				<input id="rule2" name="rule" type="radio" value="1" />送  
				<input id="songmi_guding" name="songmi" type="text" /> 米 <span class="grew999">1米=<span class="ColorRed">0.01</span>元</span>
				<div class="clears"></div>
			</li>
			<li>
				<em>每位消费者得：&nbsp;</em>
				<span class="ColorRed Font16"><strong id="gainperson">0</strong></span><span class="grew999">米</span>
			  	<div class="clears"></div>
			</li>
			<li><em>创建米票：</em><input id="mipiaocount" name="mipiaocount" type="text" /> 张<div class="clears"></div></li>
			<li>
				<em>预计发放：</em>
				<span class="ColorRed"><strong id="micount">0</strong></span>米   <span class="MarginL10">手续费：<span class="ColorRed"><strong id="poundage">0</strong></span>米</span>
			 	<div class="clears"></div>
			</li>
			<li>
				<em>有效期：</em>
				<input name="" type="radio" value="" /> 永久<span class="grew999">(直至兑换完成后活动终止)</span>
			    <div class="clears"></div>
			</li>
			<li>
				<em>&nbsp;</em>
				<input name="" type="radio" value="" /> 限时 
				<select name=""><option>2011年02月15日</option></select>至<select name=""><option>2011年02月15日</option></select>
				<div class="clears"></div>
			</li>
			<li>
				<em>备注：</em>
				<textarea name="" cols="62" rows="5"></textarea>
				<div align="center" class="ColorRed">还可以输入100字</div>
				<div class="clears"></div>
			</li>
			<li><em>&nbsp;</em><img src="../images/okandpay.gif" width="214" height="56" onclick="formsubmit();"/></li>
		</ul>
	</div>
	<input type="hidden" name="submit" value="ok">
</form>
<div class="clears"></div>

<div id="fromcomputer" style="display:none;">
	<div  class="Message" style="height:157px; width:342px;">
		<table width="100%" border="0" cellspacing="2" cellpadding="2">
			<tr>
				<td colspan="2"><img src="../images/fromPC.gif" width="200" height="28" /></td>
				<td width="36%" onclick="showurl()">使用图片网络地址</td>
			</tr>
		</table>
		<form id="layer_form" method="POST" action="mipiao_create.php?type=ajax" enctype="multipart/form-data">
		<input id="activityimg_computer" name="img_computer" type="file" style="display:none;">
		<table width="100%" border="0" cellspacing="2" cellpadding="2">
			<tr>
				<td width="68" height="79" valign="bottom"><img src="../images/upload.gif" width="68" height="67" onclick="layer_upload();"/></td>
				<td valign="bottom" class="color99">最佳尺寸300X300,小于100K</td>
			</tr>
			<tr><td></td><td align="right"><input name="" type="button" value="确 定" class="but" onclick="uploadimgsubmit()"></td></tr>
		</table>
		</form>
	</div>
</div>



<div id="fromurl" style="display:none;">
	<div  class="Message" style="height:157px; width:342px;">
		<table width="100%" border="0" cellspacing="2" cellpadding="2">
			<tr>
			  <td colspan="2" onclick="showcomputer()">从电脑上选择图片</td>
			  <td width="36%"><img src="../images/fromweb.gif" width="202" height="26" /></td>
			</tr>
		</table>
		<table width="100%" border="0" cellspacing="2" cellpadding="2">
			<tr><td height="55" valign="middle"><input name="" type="txt" value="" class="txt" style="width:280px;"></td></tr>
			<tr>
			  <td height="" valign="middle"><span class="color99">最佳尺寸300X300,小于100K</span></td>
			</tr>
			<tr><td align="right"><input name="" type="button" value="确 定" class="but" onclick="uploadimgsubmit()"></td></tr>
		</table>
	</div>
</div>
</div>
<div class="clears"></div>
<script>
$(function(){
	var songmi 
	$("#songmi_dongtai").blur(function(){
		var goodsprice = $("#goodsprice").val();
		if(goodsprice == "" || goodsprice == null){
			alert("请输入商品价格");
			$("#goodsprice").focus();
			return false;
		}
		if($("#rule1").attr("checked") == true){
			songmi = $("#songmi_dongtai").val();
			$("#gainperson").html(songmi*goodsprice);
		}
	});
	$("#songmi_guding").blur(function(){
		var goodsprice = $("#goodsprice").val();
		if(goodsprice == "" || goodsprice == null){
			alert("请输入商品价格");
			$("#goodsprice").focus();
			return false;
		}
		if($("#rule2").attr("checked") == true){
			songmi = $("#songmi_guding").val();
			$("#gainperson").html(songmi*goodsprice);
		}
	});
	$("#mipiaocount").blur(function(){
		if($("#goodsprice").val() == "" || $("#goodsprice").val() == null){
			alert("请输入商品价格");
			$("#goodsprice").focus();
			return false;
		}
		if($("#songmi_dongtai").val() == "" && $("#songmi_guding").val() == ""){
			alert("请选择兑换规则");
			return false;
		}
		var gainperson = $("#gainperson").html();
		var mipiaocount = $("#mipiaocount").val();
		var result = gainperson*mipiaocount; //预计发放米票数
		$("#micount").html(result);
		var rate = $("#rate").val();
		var poundage = result * rate 	//手续费
		var max_money = $("#max_money").val();
		//最高封顶服务费
		if(poundage > max_money){
			poundage = max_money;
		}
		$("#poundage").html(poundage);
	});
});

function artdialogclose(){
	var list = art.dialog.list;
	for (var i in list) {
	    list[i].close();
	};
}

function uploadimg(){
	artdialogclose();
	art.dialog({
		title:'',
		id:'uploadimg',
		left:'70%',
		top:"56%",
		content: $("#fromcomputer").html(),
		padding: 0,
		//background: '#FFF', // 背景色
		opacity: 0.87
		});
	$(".aui_close").hide();
}

function showcomputer(){
	artdialogclose();
	art.dialog({
		title:'',
		id:'showcomputer',
		left:'70%',
		top:"56%",
		content: $("#fromcomputer").html(),
		padding: 0,
		//background: '#FFF', // 背景色
		opacity: 0.87
	});
	$(".aui_close").hide();
}

function showurl(){
	artdialogclose();
	art.dialog({
		title:'',
		id:'showurl',
		left:'70%',
		top:"56%",
		content: $("#fromurl").html(),
		padding: 0,
		//background: '#FFF', // 背景色
		opacity: 0.87
	});
	$(".aui_close").hide();
}

function uploadimgsubmit(){
	$("#layer_form").ajaxSubmit({
		success:function(s){
			$("#activityimg").val(s);
			artdialogclose();
		}
	});	
}

function layer_upload(){
	$("#activityimg_computer").click();
}

function checkPic() {
	var picPath = document.getElementById("pic").value;
	var type = picPath.substring(picPath.lastIndexOf(".") + 1, picPath.length).toLowerCase();
	if (type != "jpg" && type != "bmp" && type != "gif" && type != "png") {
		alert("请上传正确的图片格式");
		return false;
	}
	return true;
}

//图片预览
function PreviewImage(divImage, upload, width, height) {
	if (checkPic()) {
		try {
			var imgPath;      //图片路径
			var Browser_Agent = navigator.userAgent;//判断浏览器的类型
				if (Browser_Agent.indexOf("Firefox") != -1) {//火狐浏览器		
				document.getElementById(divImage).innerHTML ="";
				document.getElementById(divImage).innerHTML = "<img id='imgPreview'  width='" + width + "' height='" + height + "'/>";
				var imgObjPreview=document.getElementById("imgPreview");
				imgObjPreview.src = window.URL.createObjectURL(upload.files[0]);
			} else { //IE浏览器 ie9 必须在兼容模式下才能显示预览图片
				var Preview = document.getElementById(divImage);
				document.getElementById(divImage).innerHTML ="";
				Preview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = upload.value;
				Preview.style.width = width;
				Preview.style.height = height;
			}
		} catch (e) {
			alert("请上传正确的图片格式");
		}
	}
}

function formsubmit(){
	//alert(document.forms[0].innerHTML)
	$("form").submit();
	//document.forms[0].submit(); 
	alert("^_^提交成功！");   
}
</script>
<?php
include("../template/".MOBAN."/footer.tpl.php");
?>
